﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Collections.Generic;
using Entity;
using BAL;
using Common;
namespace Web
{
    public partial class ExamPaper : System.Web.UI.Page
    {
        public static Module_Page Pages = new Module_Page();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!UserValidate.CheckLogin(this.Request, "MasterUser"))
            {
                Response.Write("<script type=\"text/javascript\">top.location.href='login.aspx';</script>");
                Response.Redirect("login.aspx");
                Response.End();
            }

            if (Request.QueryString["page"] != null && Request.QueryString["page"] != string.Empty)
            {
                if (PageValidate.IsNumber(Request.QueryString["page"]))
                {
                    Pages.PageNum = int.Parse(Request.QueryString["page"]);
                }
            }
            if (!IsPostBack)
            {
                BindStatusList();
                LoadList();
            }
        }

        protected void LoadList()
        {
            Pages.AllCount = BAL.ExamPaper.GetT1Count();
            Pages.PageSize = 20;
            Pages.PageName = "ExamPaper.aspx?page=";
            Pages.Compute();
            PageLabel.Text = Pages.GetPage();
            IList<ExamPaperInfo> userinfos = BAL.ExamPaper.GetList(Pages.First, Pages.Max);
            UserLists.DataSource = userinfos;
            UserLists.DataBind();
        }

        protected void lbSubject_DataBinding(object sender, EventArgs e)
        {
            Label lb = sender as Label;
            if (lb != null)
            {
                try
                {
                    if (lb.Text == "" || lb.Text == "0")
                    {
                        lb.Text = "";
                    }

                    SubjectInfo item = Subject.GetSubjectInfoById(int.Parse(lb.Text));
                    if (item != null && item.Id != 0)
                    {
                        lb.Text = item.Name;
                    }
                }
                catch
                {
                    lb.Text = "";
                }
            }
        }
        protected void lbGrade_DataBinding(object sender, EventArgs e)
        {
            //Label lb = sender as Label;
            //if (lb != null)
            //{
            //    try
            //    {
            //        if (lb.Text == "" || lb.Text == "0")
            //        {
            //            lb.Text = "";
            //        }

            //        GradeInfo item = Grade.GetGradeInfoById(int.Parse(lb.Text));
            //        if (item != null && item.Id != 0)
            //        {
            //            lb.Text = item.Name;
            //        }
            //    }
            //    catch
            //    {
            //        lb.Text = "";
            //    }
            //}
        }
        protected void lbPolicy_DataBinding(object sender, EventArgs e)
        {
            Label lb = sender as Label;
            if (lb != null)
            {
                try
                {
                    if (lb.Text == "" || lb.Text == "0")
                    {
                        lb.Text = "";
                    }
                    TestPaperPolicyMainInfo item = TestPaperPolicyMain.GetT1(int.Parse(lb.Text));
                    if (item != null && item.Id != 0)
                    {
                        lb.Text = item.Name;
                    }
                }
                catch
                {
                    lb.Text = "";
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (PageValidate.IsEmpty(this.StatusList.SelectedValue))
            {
                Utility.ShowJsAlert("请至少选择一项", this);
            }
            else
            {
                Module_File.SaveConfig(CheckBoxListHelper.SelectedValue(this.StatusList));
                Utility.ShowJsAlert("已保存", this);
            }
        }
        private void BindStatusList()
        {
            IDictionary<int, string> dic = Status.GetDic();
            StatusList.Items.Clear();
            foreach (KeyValuePair<int, string> pair in dic)
            {
                ListItem item = new ListItem();
                item.Text = pair.Value;
                item.Value = pair.Key.ToString();
                StatusList.Items.Add(item);
            }
            CheckBoxListHelper.SetSelectedValue(StatusList, Module_File.GetConfig());
        }
    }
}

